package cn.thornbird.orgsync.model;

import cn.thornbird.orgsync.util.JsonUtil;

import lombok.Data;
import org.springframework.http.HttpStatus;

@Data
public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    public static Result<Object> success() {
        return success(null);
    }

    @Override
    public String toString() {
        return JsonUtil.toJsonString(this);
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(HttpStatus.OK.value());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(Integer code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

}
